﻿using System;
using System.Threading.Tasks;
using Plugins.FormicArch.Core.AssetsCenter;
using Runtime.DesignPattern;
using UnityEngine;
using UnityEngine.AddressableAssets;

namespace  FormicArch.Core.AssetsCenter
{
    public class AssetLoader : GameSingleton<AssetLoader>, IAssetLoader
    {
        IAssetLoaderHelper _assetLoaderHelper = new AssetLoaderHelper();

        public static T LoadAsset<T>(string assetName)
        {
            return Inst._LoadAsset<T>(assetName);
        }

        public static async Task<T> LoadAssetAsync<T>(string assetName)
        {
            return await Inst._LoadAssetAsync<T>(assetName);
        }
        public static void LoadAssetAsync<T>(string assetName,Action<T> callback)
        {
            Inst._LoadAssetAsync<T>(assetName, callback);
        }
        public static GameObject Instantiate(string assetName)
        {
            return Inst._Instantiate(assetName);
        }

        public static async Task<GameObject> InstantiateAsync(string assetName)
        {
            return await Inst._InstantiateAsync(assetName);
        }
        public static void InstantiateAsync(string assetName,Action<GameObject> callback)
        {
             Inst._InstantiateAsync(assetName,callback);
        }
        public static bool ReleaseInstance(GameObject obj)
        {
            return Inst._ReleaseInstance(obj);
        }
        
        
        private T _LoadAsset<T>(string assetName)
        {
            return _assetLoaderHelper.LoadAsset<T>(assetName);
        }

        private async Task<T> _LoadAssetAsync<T>(string assetName)
        {
            return await _assetLoaderHelper.LoadAssetAsync<T>(assetName);
        }
        private void _LoadAssetAsync<T>(string assetName,Action<T> callback)
        {
             _assetLoaderHelper.LoadAssetAsync<T>(assetName,callback);
        }
        private GameObject _Instantiate(string assetName)
        {
            return _assetLoaderHelper.Instantiate(assetName);
        }

        private async Task<GameObject> _InstantiateAsync(string assetName)
        {
            return await _assetLoaderHelper.InstantiateAsync(assetName);
        }
        private void _InstantiateAsync(string assetName, Action<GameObject> callback)
        {
             _assetLoaderHelper.InstantiateAsync(assetName,callback);
        }
        private bool _ReleaseInstance(GameObject obj)
        {
            return _assetLoaderHelper.ReleaseInstance(obj);
        }
    }
}